package com.lfs.adapter.config;

import com.pdd.pop.sdk.http.HttpClientConfig;
import com.pdd.pop.sdk.http.PopHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PddConfig {

    @Value("${pdd.clientId:123}")
    private String clientId;

    @Value("${pdd.clientSecret:123}")
    private String clientSecret;

    @Value("${pdd.connectionTimeOut:2000}")
    private int connectionTimeOut;

    @Value("${pdd.socketTimeOut:2000}")
    private int socketTimeOut;

    @Value("${pdd.connectionRequestTimeOut:1000}")
    private int connectionRequestTimeOut;

    @Bean
    public PopHttpClient popHttpClient() {
        HttpClientConfig config = HttpClientConfig.getDefault();
        config.setConnectionTimeoutMillis(connectionTimeOut);
        config.setSocketTimeoutMillis(socketTimeOut);
        config.setConnectionRequestTimeout(connectionRequestTimeOut);
        return new PopHttpClient(clientId, clientSecret, config);
    }
}
